<?php

/** 
 * 
 */
class Wxpay extends CI_Controller {
	
	/**
	 */
	public function __construct() {
		parent::__construct ();
	}
	
	public function log(){
		$root = APPPATH.'logs/wxCallbackXML/';
		$date = $this->input->get('d',TRUE);
		$file = $this->input->get('f',TRUE);
		
		if ( empty($date) ) {
			$dateList = $this->getDirList($root);
			$temp['dateList'] = $dateList;
			$this->load->view('admin/wxpay/log',$temp);
		}else if ( empty($file) ) {
			$dir = $root.$date;
			$list = $this->getDirList($dir);
			foreach ($list as $v){
				echo sprintf('<li><a href="?d=%s&f=%s" target="content">%s</a></li>',$date,$v,$v);
			}
		}else{
			$file = $root.$date.'/'.$file;
			if (  file_exists($file) ) {
				$xml = file_get_contents($file);
				header('Content-type:application/xml');
				echo $xml;
			}
		}
		
		
		
	}
	
	private function getDirList($dir){
		$list = array();
		if( ! is_dir($dir) ){
			return $list;
		}
		$dh = opendir($dir);
		while ( ($file = readdir($dh)) !==FALSE ) {
			if ( $file[0]=='.' ) continue;
			$list[] = $file;
		}
		sort($list);
		return $list;
	}
	
	
	
}

